package fr.fermeManager.library.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5
{
    private static String encode(String password)
    {
        byte[] uniqueKey = password.getBytes();
        byte[] hash      = null;

        try
        {
            hash = MessageDigest.getInstance("MD5").digest(uniqueKey);
        }
        catch (NoSuchAlgorithmException e)
        {
            throw new Error("No MD5 support in this VM.");
        }

        StringBuilder hashString = new StringBuilder();
        for (int i = 0; i < hash.length; i++)
        {
            String hex = Integer.toHexString(0xFF & hash[i]);
            hashString.append(hex);
        }
        return hashString.toString();
    }

    public static void main(String[] args)
    {
        String toEncode = "dateDeNaissance";

        System.out.println("Original string ... " + toEncode);
        System.out.println("String MD5 ........ " + encode(toEncode));
    }
}